const cloud = require('wx-server-sdk')

cloud.init()

exports.main = async (event) => {
  const name = event.name;

  if (name == null) {
    return {
      code: -1
    };
  }
  
  const db = cloud.database();
  const res = await db.collection('books').where({
    title: db.RegExp({
      regexp: name,
      options: 'i'
    })
  }).get();

  return {
    code: 0,
    result: res
  }
}
